<?php
class Place_Model_SaleUserTeam extends Zend_Db_Table{
    protected $_name  = "sale_user_team";
    protected $_primary = "sale_user_team_id";
    
    public function getTeamOfUser($userId){
        $normalUtils = new My_Utils_NormalUtils();
        $DB = $normalUtils->getNormalDb(1);
        $registry   = Zend_Registry::getInstance();
        $query = $DB    ->select()
                        ->from(array('t'=>'sale_user_team'),
                                array('sale_team_id'))
                        ->where('sale_user_id = ?', $userId);
        $teamResult = $DB->fetchAll($query);
        $result = array();
        foreach ($teamResult as $key => $value) {
            array_push($result, $value->sale_team_id);
        }
        return $result;
    }
    
    public function getSaleUserAndTeam(){
        $normalUtils = new My_Utils_NormalUtils();
        $DB = $normalUtils->getNormalDb(1);
        $registry   = Zend_Registry::getInstance();
        $query = $DB    ->select()
                        ->from(array('t'=>'sale_user_team'),
                                array('sale_user_id','sale_team_id'));
        $teamResult = $DB->fetchAll($query);
        return $teamResult;     
    }
    
    public function getUserInTeam($teamId){
        $normalUtils = new My_Utils_NormalUtils();
        $DB = $normalUtils->getNormalDb(1);
        $getUserInTeam = $DB    ->select()
                                ->from(array('t'=>'sale_user_team'),
                                        array('sale_user_id'))
                                ->where('sale_team_id = ?', $teamId);
        $getUserResult = $DB->fetchAll($getUserInTeam);
        $result = array();
        foreach ($getUserResult as $key => $value) {
            array_push($result, $value->sale_user_id);
        }
        return $result;
    }
}
